#define FILEPATH "serverFile"
#include "userTask.h"
#include "threadPool.h"
#include "queue.h"
typedef struct train_s{
    int dataLength;
    char buf[1000];
}train_t;
int mysqlConnet(MYSQL *db);
int isRightToken(char *saltForToken, char *userName, char *token);
int isLegalUser(MYSQL *db, char *userName, int netFd);
int userRegister(MYSQL *db, char *userName, char *saltForToken, char *token, int netFd);
int tcpInit(char *ip, char *port, int *pSockFd);
int epollAdd(int fd, int epfd);
int epollDel(int fd, int epfd);
void *threadFunc(void *parg);
int makeWorker(threadPool_t *pThreadPool);
int handleEvent(int netFd, char* userName);
int recvn(int netFd, void *p, int n);
int download(MYSQL *db, char *argv, int netFd);
int cd(MYSQL *db, char *argv, char *curPath, char *userName, int netFd);
int ls(MYSQL *db, int curPathId, int netFd);
int removeFile(MYSQL *db, char *argv, char *curPath, char *userName, int netFd);
int pwd(char *pwd, int netFd);
int makedir(MYSQL *db, char *argv,char *curPath, int curPathId, char *userName, int netFd);
int removedir(MYSQL *db, char *commandLine, char *curPath, char *userName, int netFd);
int sendfile(char *argv,int sockFd);
int upload(MYSQL *db, char* argv, char* curPath, int netFd, int curPathId, char *userName);

/*tools*/
int getSalt(char salt[]);
int getFileName(char *fileName, const char *curPath);// user1/dir1/file --> file
int makeToken(char* salt, char* usr_name, char* token);

/*sql*/
int findIdByfileName(MYSQL *db, char *filePath);
int findMD5ByfilePath(MYSQL *db, char *filePath, char *md5);
int insertDir(MYSQL *db, char *filePath, char *userName, int curPathId);
int findChildBycurPathId(MYSQL *db, int curPathId, char *childrenName);
int findParentIdByfileName(MYSQL *db, char *curPath);
int findFileNameById(MYSQL *db, int id, char *filePath);
int isDirectoryByfileName(MYSQL *db, char *fileName, char *userName);
int isFileByfileName(MYSQL *db, char *fileName, char *userName);
int deleteFilebyfileName(MYSQL *db, char *fileName, char *userName);
int deletebyid(MYSQL *db, int curPathId);
int insertNewUser(MYSQL *db, char *userName,  char *salt, char *cryptograph);
int insertNewUserRootDir(MYSQL *db, char *userName);


/*建表*/
//create table user_login_info(idx int primary key auto_increment, usr_name varchar(255) unique key, salt varchar(30), crypt varchar(255), unique(usr_name));
//create table catalog(id int primary key auto_increment, file_name varchar(255), usr_name varchar(255), pre_id int, md5 varchar(50), unique(file_name));
